<?php
error_reporting(0);

if(isset($argv[1])){ // New movie path is given
	$movfile = substr($argv[1], strrpos($argv[1], "/")+1);
	$ext = strtolower(substr($movfile, strrpos($movfile, ".")+1));
	
	$title = substr($movfile, 0, strlen($movfile) - strlen($ext) - 1);
	// Now clean "parts" options - based on ATVFiles default config (wiki.akwardtv.org)
	$title = preg_replace("/[_\.-]+cd[_\.-]*([0-9a-d]+)/","",$title);
	$title = preg_replace("/[_\.-]+dvd[_\.-]*([0-9a-d]+)/","",$title);
	$title = preg_replace("/[_\.-]+part[_\.-]*([0-9a-d]+)/","",$title);
	$title = preg_replace("/[_\.-]*sample[_\.-]*([0-9a-d]+)/","",$title);
	$title = preg_replace("/[_\.-]*trailer[_\.-]*([0-9a-d]+)/","",$title);


	if($argv[2] != ""){
		$old_movfile = substr($argv[2], strrpos($argv[2], "/")+1);
		$old_ext = strtolower(substr($old_movfile, strrpos($old_movfile, ".")+1));
	
		$old_title = substr($old_movfile, 0, strlen($old_movfile) - strlen($old_ext) - 1);
		// Now clean "parts" options - based on ATVFiles default config (wiki.akwardtv.org)
		$old_title = preg_replace("/[_\.-]+cd[_\.-]*([0-9a-d]+)/","",$old_title);
		$old_title = preg_replace("/[_\.-]+dvd[_\.-]*([0-9a-d]+)/","",$old_title);
		$old_title = preg_replace("/[_\.-]+part[_\.-]*([0-9a-d]+)/","",$old_title);
		$old_title = preg_replace("/[_\.-]*sample[_\.-]*([0-9a-d]+)/","",$old_title);
		$old_title = preg_replace("/[_\.-]*trailer[_\.-]*([0-9a-d]+)/","",$old_title);
	}
	
	if($title == $old_title){
		if(file_exists(str_replace($ext,"jpg",$argv[1])) and !file_exists(str_replace($ext,"jpg",$argv[2]))){
			copy(str_replace($ext,"jpg",$argv[1]), str_replace($ext,"jpg",$argv[2]));
		}
		echo "1";
		exit;
	}
}
echo "0";
exit;
?>